<?php

if(!defined('IN_AACMS') || !defined('IN_ADMINCP')) {
	exit('Access Denied');
}

$purl = 'action=tool&operation='.$operation;

if($operation == 'updatecache') {

	$step = max(1, intval($_GET['step']));
	
	if($step == 1) {
		include template('tool_updatecache', 'admin');
	} elseif($step == 2) {
		if($_POST['type']) {
			$type = implode('_', $_POST['type']);
			cpmsg(cplang('tools_updatecache_waiting'), $purl.'&step=3&type='.$type, 'loading', '', FALSE);
		} else {
			cpmsg('cache_choose_is_empty', $purl, 'error');
		}
	} elseif($step == 3) {
		$type = explode('_', $_GET['type']);
		if(in_array('data', $type)) {
			include libfile('function/cache');
			updatecache();
		}
		if(in_array('tpl', $type)) {
			$tpl = dir(ROOT.'./data/tpl_cache');
			while($entry = $tpl->read()) {
				if(preg_match("/\.php$/", $entry)) {
					@unlink(ROOT.'./data/tpl_cache/'.$entry);
				}
			}
			$tpl->close();
		}
		cpmsg('update_cache_succeed', '', 'succeed', '', FALSE);
	}
}

?>